package com.ruoyi.college.service.impl;

import com.ruoyi.college.domain.Major;
import com.ruoyi.college.domain.ResearchGroup;
import com.ruoyi.college.mapper.ResearchGroupMapper;
import com.ruoyi.college.service.IMajorService;
import com.ruoyi.college.service.IResearchGroupService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 教研室信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-22
 */
@Service
public class ResearchGroupServiceImpl implements IResearchGroupService 
{
    @Autowired
    private ResearchGroupMapper researchGroupMapper;



    /**
     * 查询教研室信息
     * 
     * @param groupId 教研室信息主键
     * @return 教研室信息
     */
    @Override
    public ResearchGroup selectResearchGroupByGroupId(Long groupId)
    {
        return researchGroupMapper.selectResearchGroupByGroupId(groupId);
    }


    @Autowired
    private ISysUserService  sysUserService;

    @Autowired
    private IMajorService marjorService;

    /**
     * 查询教研室信息列表
     * 
     * @param researchGroup 教研室信息
     * @return 教研室信息
     */
    @Override
    public List<ResearchGroup> selectResearchGroupList(ResearchGroup researchGroup)
    {
        List<ResearchGroup> researchGroups = researchGroupMapper.selectResearchGroupList(researchGroup);
        researchGroups.forEach(item->{
            Long directorId = item.getDirectorId();
            SysUser sysUser = sysUserService.selectUserById(directorId);
            item.setDirector(sysUser.getUserName());
            Long majorId = item.getMajorId();
            Major major = marjorService.selectMajorByMajorId(majorId);
            item.setMajor(major.getMajorName());
        });
        return researchGroups;
    }

    /**
     * 新增教研室信息
     * 
     * @param researchGroup 教研室信息
     * @return 结果
     */
    @Override
    public int insertResearchGroup(ResearchGroup researchGroup)
    {
        researchGroup.setCreateTime(DateUtils.getNowDate());
        return researchGroupMapper.insertResearchGroup(researchGroup);
    }

    /**
     * 修改教研室信息
     * 
     * @param researchGroup 教研室信息
     * @return 结果
     */
    @Override
    public int updateResearchGroup(ResearchGroup researchGroup)
    {
        researchGroup.setUpdateTime(DateUtils.getNowDate());
        return researchGroupMapper.updateResearchGroup(researchGroup);
    }

    /**
     * 批量删除教研室信息
     * 
     * @param groupIds 需要删除的教研室信息主键
     * @return 结果
     */
    @Override
    public int deleteResearchGroupByGroupIds(String groupIds)
    {
        return researchGroupMapper.deleteResearchGroupByGroupIds(Convert.toStrArray(groupIds));
    }

    /**
     * 删除教研室信息信息
     * 
     * @param groupId 教研室信息主键
     * @return 结果
     */
    @Override
    public int deleteResearchGroupByGroupId(Long groupId)
    {
        return researchGroupMapper.deleteResearchGroupByGroupId(groupId);
    }
}
